package main.niit.dao;

import main.niit.pojo.*;
import main.niit.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Get1 {
    public List<SessionData> getall() throws Exception {
        Connection connection=JDBCUtils.getConnection();

        List<SessionData> list1= new ArrayList<>();

        PreparedStatement ps1=null;

        ResultSet resultSet1=null;
        try {
            String sql1 = "SELECT step_length_1_3_ratio, `step_length_4_6_ratio`, `step_length_7_9_ratio`,`step_length_10_30_ratio`,`step_length_30_60_ratio`,`step_length_60_ratio`  FROM session_aggr_stat;";
            ps1 = connection.prepareStatement(sql1);
            resultSet1 = ps1.executeQuery();
            while (resultSet1.next()) {
                SessionData sessionData= new SessionData();
                sessionData.setStepLength1_3Ratio(resultSet1.getDouble("step_length_1_3_ratio"));
                sessionData.setStepLength4_6Ratio(resultSet1.getDouble("step_length_4_6_ratio"));
                sessionData.setStepLength7_9Ratio(resultSet1.getDouble("step_length_7_9_ratio"));
                sessionData.setStepLength10_30Ratio(resultSet1.getDouble("step_length_10_30_ratio"));
                sessionData.setStepLength30_60Ratio(resultSet1.getDouble("step_length_30_60_ratio"));
                sessionData.setStepLength60Ratio(resultSet1.getDouble("step_length_60_ratio"));
                list1.add(sessionData);


            }
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            JDBCUtils.close(ps1,connection);
        }

        return list1;

    }
}
